package com.example.sample.activity;

import android.app.Activity;
import android.app.DownloadManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.example.app.BaseActivity;
import com.example.sample.R;

/**
 * Created by liangy on 2016/12/16.
 */
public class DownloadManagerActivity extends BaseActivity {

    private EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_method_reborn);
        View btn = findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                download();
            }
        });
        editText = (EditText)findViewById(R.id.edit);
        editText.setText("http://surl.qq.com/9PrOjy?qbsrc=51&asr=4286");
    }

    private void download(){
        DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
        String url = editText.getText().toString();
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
        request.setTitle("测试标题");
        request.setDescription("测试描述");
        try {
            dm.enqueue(request);
        } catch (IllegalArgumentException e) {
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
